package com.chenshu.mycnblog.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-04-28
 * Time：22:16
 */


public class SessionUtil {

    /**
     *
     * @param request
     * @return 用户处于登录状态就返回uid，否则返回0
     */
    public static Integer getLoginUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session != null && session.getAttribute(Constant.SESSION_USERINFO_KEY)!= null) {
            return (int) session.getAttribute(Constant.SESSION_USERINFO_KEY);
        }
        return 0;
    }
}
